package com.fengdi.mapper;

import com.fengdi.pojo.Category;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CategoryMapper {
    @Insert("INSERT INTO category(category_name, category_alias, create_user, create_time, update_time) " +
            "VALUES (#{categoryName}, #{categoryAlias}, #{userId}, #{createTime}, #{updateTime})")
    public void insert(String categoryName, String categoryAlias, Integer userId, String createTime, String updateTime);

    @Select("SELECT category_name FROM category WHERE category_alias=#{categoryNameAlias}")
    public String searchCategory(String categoryNameAlias);

    @Select("SELECT * FROM category WHERE create_user = #{userId}")
    public List<Category> selectAllCategoryByUserId(Integer userId);

    // 根据id查询
    @Select("SELECT * FROM category WHERE id = #{id}")
    public Category selectCategoryByCategoryId(Integer id);

    // 根据ID更新数据
    @Update("UPDATE category SET category_name=#{categoryName},category_alias=#{categoryAlias},update_time=#{updateTime} WHERE id=#{id}")
    public void updateCategoryById(Category category);

    // 根据ID删除
    @Delete("DELETE FROM category WHERE id=#{id}")
    void deleteCategoryById(Integer id);
}
